//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.HtmlControls;
using CommunityServer.Components;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls
{
	/// <summary>
	/// Summary description for PostRssLink.
	/// </summary>
	public class PostRssLink : BaseRssLink
	{
		int forumID;
        string title = null;
		public PostRssLink()
		{
			Post p  = Posts.GetPost(csContext.PostID, csContext.User.UserID, false);
            if(p != null)
            {
                this.forumID = p.SectionID;
                this.title = p.Subject;
            }
		}

		protected override bool IsInvalid()
		{
			return (csContext.PostID < 1);
		}

		protected override bool IsAvailableToPublic()
		{
			return Permissions.ValidatePermissions(Forums.GetForum(forumID), Permission.Read, Users.GetAnonymousUser(true));
		}

		protected override string Url
		{
			get { return ForumUrls.Instance().RssPost(forumID, csContext.PostID); }
		}

        protected override void SetRssAutoDiscovery()
        {
            Forum f = Forums.GetForum(this.forumID);
            if(f != null)
            {
                string fUrl = ForumUrls.Instance().RssForum(this.forumID, ThreadViewMode.Default);
                if(!IsAvailableToPublic())
                {
                    fUrl = SiteUrls.FormatUrlWithUserNameToken(fUrl, csContext.User, true);
                }

                SetRssAutoDiscovery(f.Name, fUrl);
               
            }
            SetRssAutoDiscovery(title, base.HRef);
        }

	}
}
